package message

import (
	"context"
	"git.mycaigou.com/gfyx/common/simplecopier"
	messageDto "git.mycaigou.com/gfyx/micro-gfyx-mp-api/infrastructure/dto/message"
	"git.mycaigou.com/gfyx/micro-gfyx-mp-api/infrastructure/repository/common/message"
	pb "git.mycaigou.com/gfyx/micro-gfyx-mp-api/proto/micro_gfyx_user_service_proto/micro-gfyx-user-service"
	"git.myscrm.cn/golang/stark/v4"
)

type VerifyCodeService struct {
	verifyCodeRepo message.VerifyCodeRepositoryIface
}

// NewVerifyCodeService
// 创建构造函数
func NewVerifyCodeService(
	verifyCodeRepo message.VerifyCodeRepositoryIface,
) VerifyCodeServiceIface {
	return &VerifyCodeService{
		verifyCodeRepo: verifyCodeRepo,
	}
}

func (s *VerifyCodeService) SendSmsCode(ctx context.Context, request *messageDto.SendSmsCodeRequest) (*messageDto.SendSmsCodeResponse, error) {
	requestPb := &pb.SendSmsRequest{}
	simplecopier.CopyToStruct(requestPb, request)
	resPb, err := s.verifyCodeRepo.SendSmsCode(ctx, requestPb)
	if err != nil {
		stark.Logger.Error(ctx, "发送短信验证码，失败:", err)
	}
	res := &messageDto.SendSmsCodeResponse{}
	simplecopier.CopyToStruct(res, resPb)
	return res, nil

}
